package com.jxw.launcher;

import android.app.Activity;
import android.app.ProgressDialog;
import android.os.AsyncTask;
import cn.qqtheme.framework.entity.Province;
import cn.qqtheme.framework.picker.AddressPicker;
import cn.qqtheme.framework.util.ConvertUtils;
import com.alibaba.fastjson.JSON;
import java.io.IOException;
import java.lang.ref.WeakReference;
import java.util.ArrayList;

/* loaded from: classes.dex */
public class AddressPickTask extends AsyncTask<String, Void, ArrayList<Province>> {
    private WeakReference<Activity> activityReference;
    private Callback callback;
    private ProgressDialog dialog;
    private String selectedProvince = "";
    private String selectedCity = "";
    private String selectedCounty = "";
    private boolean hideProvince = false;
    private boolean hideCounty = false;

    /* loaded from: classes.dex */
    public interface Callback extends AddressPicker.OnAddressPickListener {
        void onAddressInitFailed();
    }

    public AddressPickTask(Activity activity) {
        this.activityReference = new WeakReference<>(activity);
    }

    public void setHideProvince(boolean z) {
        this.hideProvince = z;
    }

    public void setHideCounty(boolean z) {
        this.hideCounty = z;
    }

    public void setCallback(Callback callback) {
        this.callback = callback;
    }

    @Override // android.os.AsyncTask
    protected void onPreExecute() {
        Activity activity = this.activityReference.get();
        if (activity == null) {
            return;
        }
        this.dialog = ProgressDialog.show(activity, null, "正在初始化数据...", true, true);
    }

    /* JADX INFO: Access modifiers changed from: protected */
    @Override // android.os.AsyncTask
    public ArrayList<Province> doInBackground(String... strArr) {
        if (strArr != null) {
            int length = strArr.length;
            if (length == 1) {
                this.selectedProvince = strArr[0];
            } else if (length == 2) {
                this.selectedProvince = strArr[0];
                this.selectedCity = strArr[1];
            } else if (length == 3) {
                this.selectedProvince = strArr[0];
                this.selectedCity = strArr[1];
                this.selectedCounty = strArr[2];
            }
        }
        ArrayList<Province> arrayList = new ArrayList<>();
        try {
            Activity activity = this.activityReference.get();
            if (activity != null) {
                arrayList.addAll(JSON.parseArray(ConvertUtils.toString(activity.getAssets().open("city.json")), Province.class));
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
        return arrayList;
    }

    /* JADX INFO: Access modifiers changed from: protected */
    @Override // android.os.AsyncTask
    public void onPostExecute(ArrayList<Province> arrayList) {
        ProgressDialog progressDialog = this.dialog;
        if (progressDialog != null) {
            progressDialog.dismiss();
        }
        if (arrayList.size() > 0) {
            Activity activity = this.activityReference.get();
            if (activity == null) {
                return;
            }
            AddressPicker addressPicker = new AddressPicker(activity, arrayList);
            addressPicker.setSubmitTextSize(activity.getResources().getDimensionPixelSize(R.dimen.x13));
            addressPicker.setCancelTextSize(activity.getResources().getDimensionPixelSize(R.dimen.x13));
            addressPicker.setCancelTextColor(-16777216);
            addressPicker.setTitleTextColor(-16777216);
            addressPicker.setTitleText("请选择地区");
            addressPicker.setTitleTextSize(activity.getResources().getDimensionPixelOffset(R.dimen.x14));
            addressPicker.setTextSize(activity.getResources().getDimensionPixelSize(R.dimen.x13));
            addressPicker.setSize(activity.getResources().getDimensionPixelSize(R.dimen.x400), activity.getResources().getDimensionPixelSize(R.dimen.x336));
            addressPicker.setHideProvince(this.hideProvince);
            addressPicker.setHideCounty(this.hideCounty);
            if (this.hideCounty) {
                addressPicker.setColumnWeight(0.33333334f, 0.6666667f);
            } else {
                addressPicker.setColumnWeight(0.25f, 0.375f, 0.375f);
            }
            addressPicker.setSelectedItem(this.selectedProvince, this.selectedCity, this.selectedCounty);
            addressPicker.setOnAddressPickListener(this.callback);
            addressPicker.show();
            return;
        }
        this.callback.onAddressInitFailed();
    }
}
